home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / m2c / SYSTEM_.h < prev    next >
C/C++ Source or Header  |  1992-08-18  |  6KB  |  227 lines

  1. /* $Id: SYSTEM_.h,v 1.7 1991/11/21 16:57:59 grosch rel grosch $ */
  2.  
  3. /************************************************************************/
  4. /*                                    */
  5. /*    If the library function alloca is available and the C programs    */
  6. /*    are compiled with the flag -DStackAlloc, then the memory space    */
  7. /*    for open array value parameters will be allocated in the stack    */
  8. /*    frame of the corresponding procedure. This temporary space    */
  9. /*    will be freed automatically when the procedure returns.        */
  10. /*    Otherwise, malloc and free will be used to allocate and        */
  11. /*    deallocate memory space for open array value parameters.    */
  12. /*                                    */
  13. /*    By default open array value parameters are copied using the    */
  14. /*    library function memcpy. This can be switched to bcopy by    */
  15. /*    compiling with the flag -DBCOPY on systems without memcpy.    */
  16. /*                                    */
  17. /************************************************************************/
  18.  
  19. # ifdef __STDC__
  20. # define ARGS(parameters)    parameters
  21. # else
  22. # define ARGS(parameters)    ()
  23. # endif
  24.  
  25. /*
  26.  *    Definition of standard constants
  27.  */
  28.  
  29. #define FALSE        ((BOOLEAN)0)
  30. #define TRUE        ((BOOLEAN)1)
  31.  
  32. #define NIL        0L
  33.  
  34. /*
  35.  *    Definition of basic types
  36.  */
  37.  
  38. typedef short        SHORTINT;
  39. typedef long        LONGINT;
  40. typedef LONGINT        INTEGER;
  41. typedef unsigned short    SHORTCARD;
  42. typedef unsigned long    LONGCARD;
  43. typedef LONGCARD    CARDINAL;
  44.  
  45. typedef unsigned char    BOOLEAN;
  46.  
  47. typedef unsigned char    CHAR;
  48.  
  49. typedef float        REAL;
  50. typedef double        LONGREAL;
  51.  
  52. /*
  53.  *    Definition of standard types
  54.  */
  55.  
  56. typedef unsigned long    BITSET;
  57.  
  58. typedef void        (*PROC)();
  59.  
  60. typedef unsigned char    WORD;
  61. typedef WORD        BYTE;
  62.  
  63. typedef char        *ADDRESS;
  64.  
  65. /*
  66.  *    Definition of standard functions
  67.  */
  68.  
  69. #define ABS(x)        ((x) < 0 ? -(x) : (x))
  70. #define ABSSC(x)    ((SHORTCARD) (x))
  71. #define ABSLC(x)    ((LONGCARD) (x))
  72. #define ABSSI(x)    ((SHORTINT) ABSLI((LONGINT) (x)))
  73.  
  74. extern LONGINT ABSLI ARGS((LONGINT x));
  75.  
  76. #define ABSR(x)        ((REAL) ABSLR(x))
  77.  
  78. extern LONGREAL ABSLR ARGS((LONGREAL x));
  79.  
  80. extern CHAR CAP ARGS((CHAR ch));
  81.  
  82. #define CHR(x)        ((CHAR) (x))
  83. #define FLOAT(x)    ((REAL) (x))
  84. #define ORD(x)        ((CARDINAL) (x))
  85. #define TRUNC(x)    ((CARDINAL) (x))
  86. #define VAL(T,x)    ((T) (x))
  87.  
  88. #define MIN_SHORTINT    (-32768)
  89. #define MAX_SHORTINT    32767
  90. #define MIN_LONGINT    (-2147483648L)
  91. #define MAX_LONGINT    2147483647L
  92. #define MIN_SHORTCARD    0
  93. #define MAX_SHORTCARD    65535
  94. #define MIN_LONGCARD    ((LONGCARD)0L)
  95. #define MAX_LONGCARD    ((LONGCARD)4294967295L)
  96.  
  97. #define MIN_BOOLEAN    FALSE
  98. #define MAX_BOOLEAN    TRUE
  99.  
  100. #define MIN_CHAR    ((CHAR)'\0')
  101. #define MAX_CHAR    ((CHAR)'\377')
  102.  
  103. #define MIN_REAL    ((REAL)1.40129846432481707e-45)
  104. #define MAX_REAL    ((REAL)3.40282346638528860e+38)
  105. #define MIN_LONGREAL    4.94065645841246544e-324
  106. #define MAX_LONGREAL    1.79769313486231470e+308
  107.  
  108. #define ODD(x)        ((BOOLEAN)((x) & 01))
  109.  
  110. /*
  111.  *    Definition of standard procedures
  112.  */
  113.  
  114. #define INC(x)        (x)++
  115. #define INC1(x,n)    x += n
  116. #define DEC(x)        (x)--
  117. #define DEC1(x,n)    x -= n
  118.  
  119. #define EXCL(s,i)    s &= ~(0X1L << (i))
  120. #define INCL(s,i)    s |= 0X1L << (i)
  121.  
  122. #define ADR(x)        ((ADDRESS) &(x))
  123. #define ADR1(x)        ((ADDRESS) (x))
  124.  
  125. /*
  126.  *    Definition of (some) set operators
  127.  */
  128.  
  129. #define SYSTEM_MaxSet        (sizeof (unsigned long) * 8 - 1)
  130.  
  131. #define SET_ELEM(el)        (0X1L << (el))
  132. #define SET_cRNG(lo,hi) \
  133.     ((lo) <= (hi) ? ~0X0L >> (lo) << (lo) + SYSTEM_MaxSet - (hi) >> SYSTEM_MaxSet - (hi) : 0X0L)
  134. #define SET_RANGE(lo,hi)    SET_RANGE1((CARDINAL)(lo), (CARDINAL)(hi))
  135.  
  136. extern unsigned long SET_RANGE1 ARGS((CARDINAL lo, CARDINAL hi));
  137.  
  138. #define SET_DIFF(s1,s2)        ((s1) & ~(s2))
  139. #define IN(x,s)            ((BOOLEAN)((s) >> (x) & 0X1L))
  140. #define SET_IS_SUBSET1(s1,s2)    ((BOOLEAN)!((s1) & ~(s2)))
  141. #define SET_IS_SUBSET2(s1,s2)    ((BOOLEAN)!((s2) & ~(s1)))
  142.  
  143. /*
  144.  *    Definition of compiler constants
  145.  */
  146.  
  147. #define SYSTEM_ALIGN        8
  148. #define SYSTEM_MASK             (~(SYSTEM_ALIGN - 1))
  149.  
  150. /*
  151.  *    Definition of compiler types
  152.  */
  153.  
  154. typedef ADDRESS        OPAQUE;
  155. typedef CHAR        *STRING;
  156.  
  157. /*
  158.  *    Definition of compiler variables
  159.  */
  160.  
  161. extern int      SYSTEM_argc;
  162. extern char    **SYSTEM_argv;
  163. extern char    **SYSTEM_envp;
  164.  
  165. /*
  166.  *    Definition of compiler macros and functions
  167.  */
  168.  
  169. #ifdef StackAlloc
  170.  
  171. #define OPEN_ARRAY_LOCALS    char *FREE_POINTER;
  172. #define ALLOC_OPEN_ARRAYS(size, arrays) \
  173.     FREE_POINTER = alloca((int)((size) + (arrays) * (SYSTEM_ALIGN - 1)));
  174. #define FREE_OPEN_ARRAYS
  175.  
  176. #else
  177.  
  178. #define OPEN_ARRAY_LOCALS    char *BLOCK_POINTER, *FREE_POINTER;
  179. #define ALLOC_OPEN_ARRAYS(size, arrays)    \
  180.     BLOCK_POINTER = FREE_POINTER = \
  181.         malloc((unsigned)((size) + (arrays) * (SYSTEM_ALIGN - 1)));
  182. #define FREE_OPEN_ARRAYS    free(BLOCK_POINTER);
  183.  
  184. #endif
  185.  
  186. # ifdef BCOPY
  187. #define COPY_OPEN_ARRAY(array, elems, type) \
  188.     { int ARRAY_SIZE = elems * sizeof(type); \
  189.       bcopy((char *)array, FREE_POINTER, ARRAY_SIZE); \
  190.       array = FREE_POINTER; \
  191.       FREE_POINTER += (ARRAY_SIZE + (SYSTEM_ALIGN - 1)) & SYSTEM_MASK; \
  192.     }
  193. # else
  194. #define COPY_OPEN_ARRAY(array, elems, type) \
  195.     { int ARRAY_SIZE = elems * sizeof(type); \
  196.       array = (type *)memcpy(FREE_POINTER, (char *)array, ARRAY_SIZE); \
  197.       FREE_POINTER += (ARRAY_SIZE + (SYSTEM_ALIGN - 1)) & SYSTEM_MASK; \
  198.     }
  199. # endif
  200.  
  201. #define FOR_LIMIT_UP(last, step, min) \
  202.     ((last) < (min) + ((step) - 1) ? (min) : (last) - ((step) - 1))
  203.  
  204. #define FOR_LIMIT_DOWN(last, step, max) \
  205.     ((last) > (max) + ((step) + 1) ? (max) : (last) - ((step) + 1))
  206.  
  207. extern void CaseError ARGS((char file[], int line));
  208. extern void ReturnError ARGS((char file[], int line));
  209.  
  210. /*
  211.  *    Definition of library functions
  212.  */
  213.  
  214. #ifdef StackAlloc
  215. extern char *alloca();
  216. #else
  217. /* #include "malloc.h"    */
  218. extern char *malloc();
  219. extern void free();
  220. #endif
  221.  
  222. # ifndef BCOPY
  223. extern char *memcpy();
  224. # endif
  225. extern char *strncpy();
  226. extern void exit();
  227.